<template>
	<view class="integral">
		<u-tabs v-if="isclub" :list="list1"
			itemStyle="padding-left: 32rpx; padding-right: 32rpx; height: 80rpx;background: #fff;"
			:activeStyle="{color: '#000000',fontWeight: 'bold'}" :lineColor="'#FC6758'" @click="click">
		</u-tabs>

		<view class="content_box">
			<view class="top">
				<view v-if="act==2" class="top_box">
					<view class="top_left">
						<view class="small">
							牛果
						</view>
						<view class="num">
							{{po}}
						</view>
					</view>
					<view class="top_right">
						<view @click="goexchange" class="btn">
							兑换
						</view>
					</view>
				</view>
				<view v-if="act==2" class="ms_juan">
					代金券：{{juan}}
				</view>
				<view v-else class="top_box">
					<view class="top_left">
						<view class="small">
							团队牛果
						</view>
						<view class="num">
							{{clpo}}
						</view>
					</view>
				</view>
			</view>

			<view class="title">
				<text>牛果明细</text>
				<text @click="gointerList" class="more">更多</text>
			</view>

			<view v-if="act==1" class="list_box">
				<view v-for="(item,index) in cplist" class="list_item">
					<view class="item_left">
						<image src="../../static/tabsIcon/niuguo.png" mode=""></image>
						<view class="left_info">
							<view class="name">
								{{item.content}}
							</view>
							<view class="time">
								{{item.gmtCreate | times}}
							</view>
						</view>
					</view>
					<view class="item_right">
						{{item.isIncrease==1?'+':'-'}} {{item.pointsNum}}
					</view>
				</view>
			</view>

			<view v-if="act==2" class="list_box">
				<view v-for="(item,index) in polist" class="list_item">
					<view class="item_left">
						<image src="../../static/tabsIcon/niuguo.png" mode=""></image>
						<view class="left_info">
							<view class="name">
								{{item.content}}
							</view>
							<view class="time">
								{{item.gmtCreate | times}}
							</view>
						</view>
					</view>
					<view class="item_right">
						{{item.isIncrease==1?'+':'-'}} {{item.pointsNum}}
					</view>
				</view>
			</view>

		</view>
	</view>
</template>

<script>
	import {
		clubpolist,
		pointslist,
		exchangeslist,
		getinfo
	} from '@/api/mine'
	export default {
		data() {
			return {
				exlist: [],
				polist: [],
				cplist: [],
				isclub: false,
				juan: 0,
				clpo: 0,
				po: 0,
				src: "../../static/tabsIcon/jifen.png",
				act: 2,
				list1: [{
						name: '团队牛果',
						value: 1
					},
					{
						name: '个人牛果',
						value: 2
					}
				]
			}
		},
		filters: {
			times(value) {
				let date = new Date(value);
				let y = date.getFullYear(); // 年
				let MM = date.getMonth() + 1; // 月
				MM = MM < 10 ? ('0' + MM) : MM;
				let d = date.getDate(); // 日
				d = d < 10 ? ('0' + d) : d;
				let h = date.getHours(); // 时
				h = h < 10 ? ('0' + h) : h;
				let m = date.getMinutes(); // 分
				m = m < 10 ? ('0' + m) : m;
				let s = date.getSeconds(); // 秒
				s = s < 10 ? ('0' + s) : s;
				// var timer =  y + '-' + MM + '-' + d + ' ' + h + ':' + m + ':' + s;
				var timer = y + '-' + MM + '-' + d;
				return timer;
			}
		},
		// onLoad() {
		// 	this.getclub();
		// 	// this.getexlist();
		// 	this.getpolist();
		// 	this.getinfo();
		// },
		onShow() {
			this.getclub();
			// this.getexlist();
			this.getpolist();
			this.getinfo();
		},
		methods: {
			getinfo() {
				getinfo().then(res => {
					if (res.success == 1) {
						this.po = res.data.integral;
						// this.juan = res.data.couponAmount;
						this.juan = res.data.couponNumber;
					} else {
						uni.showToast({
							icon: 'none',
							title: res.message
						})
					}
				})
			},
			goexchange() {
				uni.navigateTo({
					url: "./exchange"
				})
			},
			getclub() {
				let data = {
					pageNum: 1,
					pageSize: 10
				}
				clubpolist(data).then(res => {
					if (res.success == 1) {
						if (res.data.exist == 1) {
							this.act = 1;
							this.cplist = res.data.iPage.records;
							this.isclub = true;
							this.clpo = res.data.clubIntegral;
						} else {
							this.act = 2;
						}

					} else {
						uni.showToast({
							icon: 'none',
							title: res.message
						})
					}
				})
			},
			getpolist() {
				let data = {
					pageNum: 1,
					pageSize: 10
				}
				pointslist(data).then(res => {
					if (res.success == 1) {
						this.polist = res.data.records;
					} else {
						uni.showToast({
							icon: 'none',
							title: res.message
						})
					}
				})
			},
			getexlist() {
				let data = {
					pageNum: 1,
					pageSize: 3
				}
				exchangeslist(data).then(res => {
					if (res.success == 1) {
						this.exlist = res.data.records;
					} else {
						uni.showToast({
							icon: 'none',
							title: res.message
						})
					}
				})
			},
			click(item) {
				this.act = item.value
			},
			gointerList() {
				if (this.act == 1) {
					uni.navigateTo({
						url: "./ClubintegralList"
					})
				} else {
					uni.navigateTo({
						url: "./integralList"
					})
				}

			},
			goexchangeList() {
				uni.navigateTo({
					url: "./exchangeList"
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	page {
		background: #f4f4f4;
	}

	.integral {
		// width: 100%;
		// background-image: url(../../static/tabsIcon/mybg.webp);
		// background-repeat: no-repeat;
		// background-size: 100% 420rpx;
		// min-height: 80vh;
		// padding: 30rpx;
	}

	.content_box {
		padding: 30rpx;
		// width: 100%;
	}

	.top {
		background-image: url(../../static/tabsIcon/otherbg.png);
		background-repeat: no-repeat;
		background-size: 100% 100%;
		// width: 100%;
		height: 300rpx;
		color: #FFFFFF;
		padding: 50rpx;

		// display: flex;
		// align-items: center;
		// justify-content: center;
		// text-align: center;
		.top_box {
			display: flex;
			align-items: flex-start;
			justify-content: space-between;
		}

		.small {
			font-size: 28rpx;
			margin-bottom: 10rpx;
		}

		.num {
			font-size: 60rpx;
		}

		.btn {
			width: 150rpx;
			height: 50rpx;
			line-height: 50rpx;
			text-align: center;
			background: linear-gradient(90deg, #E33F33 0%, #EE6157 100%);
			font-size: 26rpx;
			border-radius: 20rpx;
		}

		.ms_juan {
			margin-top: 100rpx;
			font-size: 28rpx;
		}
	}

	.title {
		color: #333333;
		margin: 30rpx 0;
		font-size: 32rpx;
		display: flex;
		align-items: flex-end;
		justify-content: space-between;

		.more {
			font-size: 28rpx;
		}
	}

	.list_box {
		margin-bottom: 40rpx;

		.list_item {
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 30rpx;
			background: #FFF;
			margin-bottom: 20rpx;

			.item_left {
				display: flex;
				align-items: center;

				image {
					width: 68rpx;
					height: 68rpx;
					margin-right: 15rpx;
				}

				.name {
					color: #333333;
					font-size: 30rpx;
				}

				.time {
					color: #999999;
					font-size: 24rpx;
				}
			}

			.item_right {
				color: #333333;
				font-size: 34rpx;
			}
		}
	}
</style>
